***Replication File for LSQ 
** Female Turnover Analysis for "Already Gone"	
	*Jordan Butcher (and Noah Haynes)
	
** Created: 2.10.22
** Modified: 4.25.23
** Final Prep for LSQ Dataverse: 7.31.23

cd " "

use "Female Turnover Dataset_foranalysis", clear

*scaling down components of professionalization 
gen salnew = sal16/1000
gen daysnew = realavgday
gen bi_femleader = fem_leaders
	recode bi_femleader (2 = 1) (3 = 1) (1 = 1) (else = 0)

*binary TL variable 
gen TL = 1 if divided == 1 | unified == 1
recode TL (. = 0)

* male proportional variable 
gen male_leave = total_turnover - fem_leave
gen maleturn_male = (male_leave/maleseat)*100

gen propmale = male_leave/total_turnover
gen propfem = fem_leave/total_turnover

tabstat propfem propmale, by(state)
tabstat pr_femseat pr_maleseat, by(state)

*getting relative turnover rates (0 = equal proportion of men and women turning, + is a higher prop of women, - is a higher prop of men)

gen house_relativeturn = femturn_fem_house - maleturn_male_house 
gen sen_relativeturn = femturn_fem_sen - maleturn_male_sen

*********************************************
***Testing Full Model
*xtreg using re, because there are national trends that need to be accounted for in the error term, not just effects within units...allows for the time invariant controls
	
	*female turnover out of total turnover in the legislature 
	xtreg femturn_tot salnew realavgday leg_staff fem_leaders per_uncontested per_safe southernstates career consecutive life calculatedranney pr_femseat, cluster(state) re
			*2 states are missing, need to find out which 
				keep if e(sample)
				*(NE and LA are missing due to election data)
		
		xttest0
			*fail to reject the null, OLS is a better fit
	
xtreg femturn_tot salnew realavgday leg_staff fem_leaders per_uncontested per_safe southernstates career consecutive life calculatedranney, cluster(state) re
estimates store random

xi: reg femturn_tot sal16 realavgday leg_staff fem_leaders per_uncontested per_safe southernstates career consecutive life calculatedranney i.state 
estimates store ols

estimates table random ols, star stats(N r2 r2_a)
	
	
*Comparing Caucus Measures	
		reg femturn_tot salnew leg_staff fem_H_protem fem_H_speaker fem_P_protem fem_S_pres bipartisan_c, cluster(state) 
		estimates store bipart 
	
		reg femturn_tot salnew leg_staff fem_H_protem fem_H_speaker fem_P_protem fem_S_pres start_caucus, cluster(state) 
		estimates store startcaucus
		
		estimates table bipart startcaucus, star stats(N r2 r2_a)
		
		*bipartisan caucus measure appears to have greater explanatory power, little affect on the other variables
	
	
	
	
***********************************************************	
		
*** ANALYSIS ***
		*using normal OLS regression, se clustered by state 
	**********************************************************************

	
*** Table 1: Comparing rates of female turnover between chambers and states with/out term limits	
		reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday TL, cluster(state)
				outreg2 using table1, title() ctitle(Lower-ALL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) replace
		
		reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday if TL == 1, cluster(state) 
				outreg2 using table1, title() ctitle(Lower-TL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
		
	   ** House- base model with time fe
	reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday TL i.year, cluster(state)
				outreg2 using table1, title() ctitle(Lower-timefe) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
		
		** House- base model with state fe
	reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday TL i.st, cluster(state)
				outreg2 using table1, title() ctitle(Lower-tstatefe) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
		
** SENATE 

		reg femturn_sen salnew leg_staff  fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday TL, cluster(state)
				outreg2 using table1, title() ctitle(Upper-ALL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
		
		reg femturn_sen salnew leg_staff  fem_P_protem fem_S_pres  bipartisan_c per_uncontested per_safe realavgday if TL == 1  , cluster(state)
				outreg2 using table1, title() ctitle(upper-TL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
				
		
	** Senate- base model with time fe
		reg femturn_sen salnew leg_staff  fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday TL i.year, cluster(state)
				outreg2 using table1, title() ctitle(Upper-timefe) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append	
	
	
		** Senate- base model with state fe
		reg femturn_sen salnew leg_staff  fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday TL i.st, cluster(state)
				outreg2 using table1, title() ctitle(Upper-statefe) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) tex append	
	
				
		
		** Total Turnover
		reg femturn_tot salnew leg_staff fem_H_protem fem_H_speaker fem_P_protem fem_S_pres bipartisan_c calculatedranney per_uncontested per_safe realavgday 
		reg femturn_tot salnew leg_staff fem_H_protem fem_H_speaker fem_P_protem fem_S_pres  bipartisan_c calculatedranney per_uncontested per_safe realavgday if TL == 1  
	
		 
	
*********	
* TABLE 2: Basic regression version of relative turnover, same coef results as xt model 
	
** LOWER 
	* NTL 	
	reg house_relativeturn salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday TL, cluster(state)
				outreg2 using table2, title() ctitle(House_all) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) replace
	
	* TL
	reg house_relativeturn salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday if TL == 1, cluster(state)
				outreg2 using table2, title() ctitle(House-TL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
** UPPER 	
	* NTL 
	reg sen_relativeturn salnew leg_staff fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday TL, cluster(state)
				outreg2 using table2, title() ctitle(Senate-all) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
	
	* TL
	reg sen_relativeturn salnew leg_staff fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday if TL == 1, cluster(state)
				outreg2 using table2, title() ctitle(Senate-TL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) tex append
		
	
	

	
	
	
	
	
	
	
	
***********************	
***Predicted probabilities: ALL states for upper and lower
	
	***LOWER 
	preserve
	qui reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday, cluster(state)
	estsimp reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday, cluster(state)
	setx (salnew leg_staff per_uncontested per_safe realavgday) mean (fem_H_protem fem_H_speaker bipartisan_c) median 
	
			*salary min=.1 and max=100
			simqi, fd(ev) changex(salnew p25 p75)
			*staff min=.35 max=17.5
			simqi, fd(ev) changex(leg_staff p25 p75)
			*change from no leaders to leader
			simqi, fd(ev) changex(fem_H_protem 0 1)
			simqi, fd(ev) changex(fem_H_speaker 0 1)
			*change from no caucus to caucus 
			simqi, fd(ev) changex(bipartisan_c 0 1)
			*change in % uncontested 
			simqi, fd(ev) changex(per_uncontested p25 p75)
			* change in days 
			simqi, fd(ev) changex(realavgday p25 p75)

	restore


	*** UPPER 
	preserve
	qui reg femturn_sen salnew leg_staff fem_S_pres fem_P_protem bipartisan_c per_uncontested per_safe realavgday, cluster(state)
	estsimp reg femturn_sen salnew leg_staff fem_S_pres fem_P_protem  bipartisan_c per_uncontested per_safe realavgday, cluster(state)
	setx (salnew leg_staff per_uncontested per_safe realavgday) mean (fem_S_pres fem_P_protem  bipartisan_c) median 
	
			*salary min=.1 and max=100
			simqi, fd(ev) changex(salnew p25 p75)
			*staff min=.35 max=17.5
			simqi, fd(ev) changex(leg_staff p25 p75)
			*change from no leaders to leader
			simqi, fd(ev) changex(fem_S_pres 0 1)
			simqi, fd(ev) changex(fem_P_protem 0 1)
			*change from no caucus to caucus 
			simqi, fd(ev) changex(bipartisan_c 0 1)
			*change in % uncontested 
			simqi, fd(ev) changex(per_uncontested p25 p75)
			* change in days 
			simqi, fd(ev) changex(realavgday p25 p75)

	restore


******************
*** Predicted probabilities: States with Term Limits
	
***LOWER 
	preserve
	qui reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday if TL == 1, cluster(state)
	estsimp reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday if TL == 1, cluster(state)
	setx (salnew leg_staff per_uncontested per_safe realavgday) mean (fem_H_protem fem_H_speaker bipartisan_c) median 
	
			*salary min=.1 and max=100
			simqi, fd(ev) changex(salnew p25 p75)
			*staff min=.35 max=17.5
			simqi, fd(ev) changex(leg_staff p25 p75)
			*change from no leaders to leader
			simqi, fd(ev) changex(fem_H_protem 0 1)
			simqi, fd(ev) changex(fem_H_speaker 0 1)
			*change from no caucus to caucus 
			simqi, fd(ev) changex(bipartisan_c 0 1)
			*change in % uncontested 
			simqi, fd(ev) changex(per_uncontested p25 p75)
			* change in days 
			simqi, fd(ev) changex(realavgday p25 p75)

	restore



	*** UPPER 
	preserve
	qui reg femturn_sen salnew leg_staff fem_S_pres fem_P_protem bipartisan_c per_uncontested per_safe realavgday if TL == 1, cluster(state)
	estsimp reg femturn_sen salnew leg_staff fem_S_pres fem_P_protem  bipartisan_c per_uncontested per_safe realavgday if TL == 1, cluster(state)
	setx (salnew leg_staff per_uncontested per_safe realavgday) mean (fem_S_pres fem_P_protem  bipartisan_c) median 
	
			*salary min=.1 and max=100
			simqi, fd(ev) changex(salnew p25 p75)
			*staff min=.35 max=17.5
			simqi, fd(ev) changex(leg_staff p25 p75)
			*change from no leaders to leader
			simqi, fd(ev) changex(fem_S_pres 0 1)
			simqi, fd(ev) changex(fem_P_protem 0 1)
			*change from no caucus to caucus 
			simqi, fd(ev) changex(bipartisan_c 0 1)
			*change in % uncontested 
			simqi, fd(ev) changex(per_uncontested p25 p75)
			* change in days 
			simqi, fd(ev) changex(realavgday p25 p75)

	restore

************************************
************************************
************************************
*** APPENDIX ***
* Table A1 showing average turnover  
	tabstat pr_femseat femturn_tot, by(state)
	tabstat pr_femseat pr_maleseat, by(state)

	tabstat pr_femseat pr_maleseat femturn_tot maleturn_tot femturn_fem maleturn_male, by(state)
	
	
	
* Appendix A5, Alternative to Table 1 (states with TL and states w/out)
		reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday if TL == 0, cluster(state)
				outreg2 using tableA5, title() ctitle(Lower-NTL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) replace
		
		reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday if TL == 1, cluster(state) 
				outreg2 using tableA5, title() ctitle(Lower-TL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
		
	
		reg femturn_sen salnew leg_staff  fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday if TL == 0, cluster(state)
				outreg2 using tableA5, title() ctitle(Upper-NTL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
		
		reg femturn_sen salnew leg_staff  fem_P_protem fem_S_pres  bipartisan_c per_uncontested per_safe realavgday if TL == 1  , cluster(state)
				outreg2 using tableA5, title() ctitle(upper-TL) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) tex append
		
	

* Appendix A7, Alternative Models (all states) same base model as Table 1
	* A: w/ TL interaction IV's 
	* B: time fe 

	** House- interaction of TL # Salary (not sig)
	reg femturn_house c.salnew##TL leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday, cluster(state)
				outreg2 using tableA7, title() ctitle(Lower-salinter) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) replace
	
	
	** Senate- Interaction of TL # Salary (sig)
		reg femturn_sen c.salnew##TL leg_staff fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday, cluster(state)
				outreg2 using tableA7, title() ctitle(Upper-salinter) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
				
	** House- interaction of TL # pro tem leader
	reg femturn_house salnew leg_staff fem_H_protem##TL fem_H_speaker bipartisan_c per_uncontested per_safe realavgday, cluster(state)
				outreg2 using tableA7, title() ctitle(Lower-leadinter) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
	
	
	** Senate- interaction of TL # pro tem leader 
		reg femturn_sen salnew leg_staff fem_P_protem##TL fem_S_pres bipartisan_c per_uncontested per_safe realavgday, cluster(state)
				outreg2 using tableA7, title() ctitle(Upper-leadinter) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
				
	** House- interaction of TL # caucus
	reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c##TL per_uncontested per_safe realavgday, cluster(state)
				outreg2 using tableA7, title() ctitle(Lower-caucus) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
	
	
	** Senate- interaction of TL # caucus
		reg femturn_sen salnew leg_staff fem_P_protem fem_S_pres bipartisan_c##TL per_uncontested per_safe realavgday, cluster(state)
				outreg2 using tableA7, title() ctitle(Upper-caucus) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) tex append
		
		
*** Appendix Table 8 Fixed Effects		
		
	** House- base model with time fe
	reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday TL i.year, cluster(state)
				outreg2 using tableA8, title() ctitle(Lower-timefe) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) replace
	
	** Senate- base model with time fe
		reg femturn_sen salnew leg_staff  fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday TL i.year, cluster(state)
				outreg2 using tableA8, title() ctitle(Upper-timefe) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append	
	
	
	** House- base model with state fe
	reg femturn_house salnew leg_staff fem_H_protem fem_H_speaker bipartisan_c per_uncontested per_safe realavgday TL i.st, cluster(state)
				outreg2 using tableA8, title() ctitle(Lower-tstatefe) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) append
	
	** Senate- base model with state fe
		reg femturn_sen salnew leg_staff  fem_P_protem fem_S_pres bipartisan_c per_uncontested per_safe realavgday TL i.st, cluster(state)
				outreg2 using tableA8, title() ctitle(Upper-statefe) ///
				bdec(3) tdec(3) rdec(3) sdec(3) alpha(.01, .05, .1) tex append	
	
	
	
	